<?php

function custom_googlemap_shortcode( $atts, $content = null ) {

    extract( shortcode_atts( array(
            'id' => '0',
            'width' => '320px',
            'height' => '212px',
            'lat' => '-12.110914',
            'long' => '-77.042924',
            'zoom' => '16',
            'marker_html' => ""
    ), $atts ) );

    if( isset($atts['id']) ) $id = $atts['id'];
    if( isset($atts['width']) ) $width = $atts['width'];
    if( isset($atts['height']) ) $height = $atts['height'];
    if( isset($atts['lat']) ) $lat = $atts['lat'];
    if( isset($atts['long']) ) $long = $atts['long'];
    if( isset($atts['zoom']) ) $zoom = $atts['zoom'];
    if( isset($atts['marker_html']) ) $marker_html = $atts['marker_html'];

    $output = '';
    //El script se traslado a header.php
    //$output .= '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>';
    $output .= '<div id="google-map-'.$id.'" style="';
    $output .= 'width:' . $width . ';';
    $output .= 'height:' . $height . ';';
    $output .= '"></div>';

    $output .= '<script type="text/javascript">

                    var myLatlng'.$id.' = new google.maps.LatLng('.$lat.','.$long.');
                    var mapOptions'.$id.' = {
                        zoom: ' . $zoom . ',
                        center: myLatlng'.$id.',
                        scrollwheel: true,
                        scaleControl: false,
                        disableDefaultUI: false
                    }
                    var map'.$id.' = new google.maps.Map(document.getElementById("google-map-'.$id.'"), mapOptions'.$id.');

                    var marker'.$id.' = new google.maps.Marker({
                        position: myLatlng'.$id.',
                        map: map'.$id.',
                        title: "Specchi"
                    });
                    
                    var contentString = "' . $marker_html . '";
                    var infowindow = new google.maps.InfoWindow({
                            content: contentString
                    });

                    /*google.maps.event.addListener(marker, "click", function() {
                        infowindow.open(map'.$id.',marker'.$id.');
                    });*/
                    
                </script>';

    return $output;

}

add_shortcode( 'googlemap_custom', 'custom_googlemap_shortcode' );

?>